<!DOCTYPE html>
<html>
<head>
	<!-- Google Tag Manager -->
	<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
	new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
	j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
	'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
	})(window,document,'script','dataLayer','GTM-W8KNPT4');</script>
	<!-- End Google Tag Manager -->
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width,inital-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
	<meta name="format-detection" content="telephone=no">
    <title>注册 - 博猫体育</title>
    <link rel="stylesheet" href="css/login.css?ver=1.0.000">
    <link rel="stylesheet" href="css/iconfont.css?ver=1.0.000">
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>
    <script src="js/pageLib.js"></script>
</head>
<body>
<div class="header">
	<div class="title">注册</div>
	<div class="left-btn"><a href="javascript:window.history.go(-1);"><i class="iconfont icon-guanbi"></i></a></div>
	<div class="right-btn"></div>
</div>
<div class="page-content">
	<form class="input-wrapper">
		<div class="input-shell phone"><input type="text" name="mobile" placeholder="输入您的手机号码"></div>
		<!-- <div class="input-shell code"><input type="text" name="smsverifycode" placeholder="请输入短信中的验证码"><a href="#" class="control disable" id="getSMSVerifyCode">获取验证码</a></div> -->
		<!-- 取消短信验证码验证 -->
		<div class="input-shell key last"><input type="password" name="password" placeholder="密码，6-20位"><i href="#" class="control invisible"></i></div>
		
	</form>
	<a class="submit disable" href="javascript:;">注　册</a>
	<div class="protocal">我已阅读并同意<a href="#">《足彩猫用户协议》</a></div>
</div>

</body>
<script type="text/javascript">
	$(document).ready(function(){
		var analysisRequest=function(url){
			var args = {};
			var match = null;
			var search = decodeURIComponent(url.split('?')[1]);
			var reg = /(?:([^&]+)=([^&]+))/g;
			while((match = reg.exec(search))!==null){
				args[match[1]] = match[2];
			}
			return args;// Return the object
		};
		var fromUrl=analysisRequest(window.location.href).from;
		var apiBaseUrl='http://betcat.zeeging.com';
		var password=$('.page-content .input-shell>input[name=password]');
		var mobile=$('.page-content .input-shell>input[name=mobile]');
		var smsverifycode=$('.page-content .input-shell>input[name=smsverifycode]');
		var submit=$('.page-content .submit');
		$('.page-content .control.invisible').on('click',function(e){
			if($(e.target).hasClass('visible')){
				$(e.target).removeClass('visible').prev('input[name=password]').attr('type','password');
			}
			else{
				$(e.target).addClass('visible').prev('input[name=password]').attr('type','text');
			}
		});//绑定密码可见按钮事件
		$('.page-content .input-shell>input').on('keyup',function(e){
			var mobileRegex=/^1[3-5,7,8]{1}[0-9]{9}$/;
			var passwordRegex=/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~\-\+]{6,20}$/;
			var smsVerifyCodeRegex=/^\d{6}$/;
			passwordOK=passwordRegex.test(password.val());
			mobileOK=mobileRegex.test(mobile.val());
			// smsVerifyCodeOK=smsVerifyCodeRegex.test(smsverifycode.val());
			smsVerifyCodeOK=true;
			// 取消短信验证码验证
			// console.log('key up');
			// console.log('password:'+passwordRegex.test(password.val()));
			// console.log('mobile:'+mobileRegex.test(mobile.val()));
			// console.log('smsverifycode:'+smsVerifyCodeRegex.test(smsverifycode.val()));

			if(passwordOK && mobileOK && smsVerifyCodeOK){
				if(submit.hasClass('disable'))submit.removeClass('disable').off('click').on('click',function(e){
					var target=$(e.target);
					//Generate nickname
					var generateNickname=function(){
						var date = new Date();
						var year = date.getFullYear();
						var month = date.getMonth()+1;
						var day = date.getDate();
						if(month<10) month = "0"+month;
						if(day<10) day = "0"+day;
						var dateStr = year+month+day;
						var hours = date.getHours();
						var mins = date.getMinutes();
						var secs = date.getSeconds();
						var msecs = date.getMilliseconds();
						if(hours<10) hours = "0"+hours;
						if(mins<10) mins = "0"+mins;
						if(secs<10) secs = "0"+secs;
						if(msecs<10) secs = "0"+msecs;
						return 'ArbUser_'+dateStr+hours+mins+secs+msecs+Math.round(Math.random()*1000000);
					};
					var fromUrl=pageLib.getQueryArgs(window.location.href).from;

					pageLib.api({
						action: '/v1/user/register',
						data: {
							mobile: mobile.val(),
							// sms_verify_code: smsverifycode.val(),
							// 取消短信验证码验证
							password: password.val(),
							terrace_channel: 2, // 平台渠道 1=PC 2=H5 3=IOS 4=Android
							teamwork_channel: ( pageLib.initAffiliate() || 1 )
						},
						success: function(data){
							console.log(data);
							dataLayer.push({'event':'RegSuccess','regMobile':mobile.val()});
							submit.off('click').addClass('disable').text('注册成功，正在跳转...');
							pageLib.login({
								username: mobile.val(),
								password: password.val(),
								success: function(){
									if(!!fromUrl){
										window.location.href=fromUrl;
									}
									else{
										window.location.href='/sporttery.html';
									}
								},
								failed: function(){
									window.location.href='/login.html';
								}
							});
						},
						failed: function(){
							if(submit.hasClass('disable'))submit.removeClass('disable').text('注　册').off('click').on('click');
						}
					});
					/*
					$.ajax({
						url:apiBaseUrl+'/index.php/Api/userReg?t='+new Date().getTime(),
						type:'POST',
						dataType:'json',
						data:{
							nickname:generateNickname(),
							mobile:mobile.val(),
							smsverifycode:smsverifycode.val(),
							password:password.val()
						},
						beforeSend: function(){
							if(!target.hasClass('disable'))target.off('click').addClass('disable').text('注册中...');
							//app.showIndicator();
							//这里似乎不生效
						},
						complete:function(){
							//app.hideIndicator();
						},
						success: function(data){
							//console.log(data);
							if(data.status==0){
								submit.off('click').addClass('disable').text('注册成功，正在跳转...');
								$.ajax({
									url:apiBaseUrl+'/index.php/DataServiceApi/login',
									type:'GET',
									dataType:'json',
									data:{
										mobile:mobile.val().trim(),
										password:password.val().trim(),
									},
									success: function(dataFromLogin){
										//console.log(data);
										if(dataFromLogin['status']==1){
											if(fromUrl){
												window.location.href=fromUrl;
											}
											else{
												window.location.href='/arb/';
											}
										}
										else{
											alert(dataFromLogin.msg);
											submit.on('click',submitFun).removeClass('disable').text('登　录');
										}
									}
								 });
							}
							else{
								alert('注册失败：'+data.msg);
								if(submit.hasClass('disable'))submit.removeClass('disable').text('注　册').off('click').on('click');
							}
						}
					});
					*/
				});
			}
			else{
				if(!submit.hasClass('disable'))submit.addClass('disable').off('click');
			}
			if(mobileOK){
				var target=$('#getSMSVerifyCode');

				var sendSMS=function(e){
					target=$(e.target);
					target.off('click',sendSMS);
					if(!target.hasClass('disable'))target.addClass('disable');
					pageLib.api({
						action: '/v1/user/get-register-sms',
						data: {
							mobile: mobile.val()
						},
						success: function(data){
							target.html('<span>60</span>秒后可重发');
							var counter=setInterval(function(){
									target.find('span').text(target.find('span').text()-1);
							},1000);
							setTimeout(function(){
								clearInterval(counter);
								if(target.hasClass('disable'))target.removeClass('disable');
								target.text('重发验证码');
								target.on('click',sendSMS);
							},60000);
						},
						failed: function(){
							// alert('验证短信发送失败：请不要频繁发送验证短信。');
							target.html('请<span>60</span>秒后再试');
							var counter=setInterval(function(){
									target.find('span').text(target.find('span').text()-1);
							},1000);
							setTimeout(function(){
								clearInterval(counter);
								if(target.hasClass('disable'))target.removeClass('disable');
								target.text('获取验证码');
								target.on('click',sendSMS);
							},60000);
						}
					});
					//console.log('fuck');
					/*
					$.ajax({
						url:apiBaseUrl+'/index.php/Api/sendSMSVerifyCode',
						type:'GET',
						dataType:'json',
						data:{
							dest:mobile.val()
						},
						beforeSend: function(){
							if(!target.hasClass('disable'))target.addClass('disable');
							//app.showIndicator();
							//这里似乎不生效
						},
						complete:function(){
							//app.hideIndicator();
						},
						success: function(data){
							//console.log(data);
							if(data.success==true){
								target.html('<span>60</span>秒后可重发');
								var counter=setInterval(function(){
										target.find('span').text(target.find('span').text()-1);
								},1000);
								setTimeout(function(){
									clearInterval(counter);
									if(target.hasClass('disable'))target.removeClass('disable');
									target.text('重发验证码');
									target.on('click',sendSMS);
								},60000);
							}
							else{
								alert('验证短信发送失败：请不要频繁发送验证短信。');
								target.html('请<span>60</span>秒后再试');
								var counter=setInterval(function(){
										target.find('span').text(target.find('span').text()-1);
								},1000);
								setTimeout(function(){
									clearInterval(counter);
									if(target.hasClass('disable'))target.removeClass('disable');
									target.text('获取验证码');
									target.on('click',sendSMS);
								},60000);
							}
						}
					});
					*/
				}
				
				if((target.text()=='获取验证码')&&target.hasClass('disable'))target.removeClass('disable').on('click',sendSMS);
			}
			else{
				var target=$('#getSMSVerifyCode');
				// console.log(target.text());
				if(!target.hasClass('disable'))target.addClass('disable');
				$('#getSMSVerifyCode').off('click');
			}
			
		});//表单验证
	})
</script>
</html>